<!DOCTYPE html>
<html lang="en">
<head>
    <meta  http-equiv="content-type" content="text/html" charset="utf-8"/>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript">
        /**
         * 原型继承
         * 特点：即继承了父类的模板，也继承了父类的原型对象
         * 但是有个缺点：跟面向对象语言有点别扭   此处是通过原型传入参数
         *

        //父类
        function Person(name,age){
            this.name = name;
            this.age = age;

        }
        Person.prototype.id = 10;
        //子类
        function Boy(){
            this.sex = sex;
        }
        Boy.prototype = new Person('zs',45);//原型继承方式 */


        /**
         * 类继承
         * 特点：只继承模板，不继承原型对象：借用构造函数的方式继承;
         *

        //父类
        function Person(name,age){
            this.name = name;
            this.age = age;

        }
        //子类
        function Boy(name,age){
            //call apply
            Person.call(this,name,age);
            this.sex = sex;
        }
        var b = new Boy('zhangsan',23,'nan');*/

        /**
         * 混合继承：前两者的结合
         */
        //父类
        function Person(name,age){
            this.name = name;
            this.age = age;
        }
        Person.prototype.id = 10;
        Person.prototype.sayName = function(){
            alert(this.name);
        }
        //子类
        function Boy(name,age,sex){
            //call apply
            Person.call(this,name,age);//1.借用构造函数继承:继承父类的模板
            this.sex = sex;
        }
        //2.原型继承
        Boy.prototype = new Person();

        var b = new Boy('李四',30,'男');
        alert(b.name);
        alert(b.sex);
        b.sayName();

    </script>
</head>
<body>

</body>
</html>